﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HFController;

namespace HFWebManage.LegalAffairs
{
    public partial class LegalAffairsBiglClass : HFController.BagePages
    {
        /// <summary>
        /// 列表
        /// </summary>
        public List<hf.Model. LegalAffairsBiglClass> list = new List<hf.Model.LegalAffairsBiglClass>();

        protected void Page_Load(object sender, EventArgs e)
        {
            //判断管理员有没有登录，如果没登录，踢出
            this.checkAdminIsLogin();

            //是否首次加载
            if (!Page.IsPostBack)
            {
                string PageStr = "";
                list = LegalAffairsController.getController().getLegalAffairsBiglClassList(out PageStr);
                pager.Text = PageStr;
                this.bindLegalAffairs();
                lblLegalAffairsID.Items.Insert(0, new ListItem("--请选择--", "0"));

                //获取Action参数，判断是修改还是删除
                string Action = this.GetQuery("action");

                switch (Action)
                {
                    case "modify":
                        //表示修改
                        this.bindmodel();
                        break;
                    case "delete":
                        //表示删除
                        int ID = int.Parse(this.GetQuery("ID"));
                        LegalAffairsController.getController().doDelegeLegalAffairsBiglClass(ID);
                        break;
                }
            }
        }

        /// <summary>
        /// 定义一个方法，绑定法律事务
        /// </summary>
        private void bindLegalAffairs()
        {
            lblLegalAffairsID.DataSource = LegalAffairsController.getController().getLegalAffairsList(100);//绑定数据源（下拉框支持List<>类型直接绑定）
            lblLegalAffairsID.DataValueField = "ID"; //下拉列表的值，用他写到数据库
            lblLegalAffairsID.DataTextField = "LegalAffairsTitle"; //下拉列表的显示文字，和要绑定的数据库字段一致
            lblLegalAffairsID.DataBind(); //执行绑定
        }

        /// <summary>
        /// 绑定需要修改的数据
        /// (就是点击修改某条记录，把上面的修改文本的信息，设置成你点的这条记录)
        /// </summary>
        private void bindmodel()
        {
            int ID = int.Parse(this.GetQuery("ID"));
            //得到这条记录
            hf.Model.LegalAffairsBiglClass model = LegalAffairsController.getController().getLegalAffairsBiglClassModel(ID);
            //输入框赋值
            lblClassName.Text = model.ClassName;
            lblLegalAffairsID.SelectedValue = model.LegalAffairsID.ToString();
            //隐藏域ID赋值
            IDS.Value = model.ID.ToString();
        }

        /// <summary>
        /// 获得事务名称
        /// </summary>
        /// <param name="ID">事务ID</param>
        /// <returns></returns>
        public string getLegalAffairsTitle(int ID)
        {
            //得到事务
            hf.Model.LegalAffairs model = LegalAffairsController.getController().getLegalAffairsModel(ID);
            //返回标题
            // return model.LegalAffairsTitle;
            if (model != null)
            {
                return model.LegalAffairsTitle;
            }
            else
            {
                return "";
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //获取Action参数，判断是修改还是保存
            string Action = this.GetQuery("action");
            if (Action == "modify")
            {
                //修改记录，刚才bindmodel()方法里，赋值的那两个
                LegalAffairsController.getController().doModifyLegalAffairsBiglClass(int.Parse(IDS.Value), lblClassName.Text, lblLegalAffairsID.SelectedValue);
            }
            else
            {
                LegalAffairsController.getController().doAddLegalAffairsBiglClass(lblClassName.Text,lblLegalAffairsID.SelectedValue);
            }
        }
    }
}